package org.example.sep_24;

public class Topic_1833 {
    public static void main(String[] args) {
        int[] costs1 = {10,2,10,10,10,10,8,2,7,8};
        int coins1 = 25;
        System.out.println(new Topic_1833().maxIceCream(costs1, coins1));
    }
    public int maxIceCream(int[] costs, int coins) {
        int[] f = new int[100001];
        for(int num : costs){
            f[num]++;
        }
        int max = 0;
        for (int i = 1; i < 100001; i++) {
            if(f[i] > 0){
                if (coins - f[i] * i >= 0){
                    max+=f[i];
                    coins -= f[i] * i;
                }else {
                    for (int j = 0; j < f[i] ; j++) {
                        if (coins - i >= 0){
                            max++;
                            f[i]--;
                            coins-=i;
                        }else {
                            break;
                        }
                    }
                }
            }
        }
        return max;
    }
}
